package com.kyzh.core.dialog

import android.util.Log
import androidx.fragment.app.FragmentActivity
import androidx.viewpager2.adapter.FragmentStateAdapter
import com.google.android.material.bottomsheet.BottomSheetDialog
import com.google.android.material.tabs.TabLayoutMediator
import com.jeremyliao.liveeventbus.LiveEventBus
import com.kyzh.core.R
import com.kyzh.core.databinding.DialogCommunitylistBinding
import com.kyzh.core.pager.weal.community.DialogCommunityListFragment
var  communitydialog :BottomSheetDialog?=null
fun FragmentActivity. showCommunityListDialog(){
    communitydialog = BottomSheetDialog(this, R.style.dialogSoftInput1)
    val dialogDB = DialogCommunitylistBinding.inflate(layoutInflater)
    val title = arrayListOf("全部社区","我关注的社区")
    dialogDB.apply {
        val mediator  = TabLayoutMediator( tab,  viewpager) { tab, position -> //这里可以自定义TabView
            tab.text =title[position]
        }
         viewpager.adapter=object : FragmentStateAdapter(this@showCommunityListDialog){
             override fun getItemCount()=2
             override fun createFragment(position: Int)= DialogCommunityListFragment.newInstance(position)
         }
        close.setOnClickListener {
            communitydialog?.dismiss()
        }
        mediator.attach()
    }
    communitydialog?.setContentView(dialogDB.root)
    communitydialog?.show()

    LiveEventBus.get<Int?>("communitylist").observe(this){
        Log.e("TAG", "showCommunityListDialog: ", )
        communitydialog?.dismiss()
    }


}

